﻿using System;
using System.Collections.Generic;
#if NETFX_CORE
using Windows.Foundation;
#else
using System.Drawing;
using System.Drawing.Imaging;
#endif
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Cofe.Core.Utils;
using Cofe.Core.Validater;


namespace Cofe.Core
{
    #if !NETFX_CORE
    public static class IconPropertiesExtension
    {
        public static Size GetDefaultSize(this CofeIconProperties property)
        {
            foreach (IPropertyValidator propValidater in IPropertyValidaterExtension.GetPropertyValidaters(property))
                if (propValidater is BitmapSizeAttribute)
                {
                    BitmapSizeAttribute bitmapSizeAttribute = propValidater as BitmapSizeAttribute;
                    return new Size(bitmapSizeAttribute.Width, bitmapSizeAttribute.Height);
                }
            throw new ArgumentException("BitmapSizeAttribute not found.");
        }

        public static Bitmap EnsureBitmapSize(this Bitmap input, CofeIconProperties property)
        {
            return BitmapUtils.EnsureBitmapSize(input, property.GetDefaultSize());
        }

        public static byte[] ConvertToBitmapArray(this Bitmap input, ImageFormat fmt)
        {
            MemoryStream ms = new MemoryStream();
            input.Save(ms, fmt);
            ms.Seek(0, SeekOrigin.Begin);
            return ms.ToArray();
        }

        public static byte[] ConvertToBitmapArray(this Bitmap input)
        {
            return input.ConvertToBitmapArray(ImageFormat.Png);
        }

    }
    #endif
}
